package sax;

import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import java.io.InputStream;

public class TestSAXParser {


    public static void main(String[] args) {



        try {
            //SAX解析器
            XMLReader parser= XMLReaderFactory.createXMLReader();



            //注册事件
            parser.setContentHandler(new PrintContentHandler());


            InputStream in=TestSAXParser.class
                                        .getClassLoader()
                                        .getResourceAsStream("students.xml");

            //解析文件
            parser.parse(new InputSource(in));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
